<template>
    <!-- 面包屑导航 -->
  <div class="breadcrumb">
    <ul>
		
      <li v-for="(item, index) in levelList" :key="item.path">
        <span v-if="item.redirect === 'noredirect' || index == levelList.length - 1"> {{ item.meta.title }}</span>
        <span v-else @click="handleLink(item)" class="cursor">{{ item.meta.title }}</span>
      </li>
    </ul>
  </div>
    <!-- 面包屑导航 -->
</template>
<script>

export default {
  name: 'breadcrumb',
  props: {
    breadcrumbConfig: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      levelList: null,
    }
  },
  watch: {
    $route() {
      this.getBreadcrumb();
    },
  },
  created () {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb() {
      let matched = this.$route.matched.filter((item) => item.name);
	  console.log(matched)
      const first = matched[0];
      if (first && first.name !== 'dashboard') {
        // matched = [{ path: '/dashboard', meta: { title: 'Dashboard' } }].concat(matched);
      }
      this.levelList = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false);
	  console.log(this.levelList)
    },
    handleLink(item) {
      const { redirect, path } = item;
      // console.log(redirect, path)
      if (redirect) {
        this.$router.push(redirect);
        return;
      }
      this.$router.push(path);
    },
  }
}
</script>
<style lang="scss" scoped>
.breadcrumb:after {
  clear: both;
  display: table;
  content: '';
}
$breadcrumb-height:30px;
.breadcrumb{
  font-size: 14px;
  margin-bottom: 20px;
  height: $breadcrumb-height;
  line-height: $breadcrumb-height;
  ul{
    li{
      font-weight: 400;
      font-size: 14px;
      float: left;
      min-width: 100px;
      padding: 0 10px 0 30px;
      text-align: center;
      background-color: #ffffff;
      position: relative;
      color: #4C81EB;
      &:before,&:after{
        box-sizing: content-box;
        width: 0;
        height: 0;
        padding:0;
        position: absolute;
        display: block;
        content:'';
      }
      &:before{
        top: 1px;
        left: 0;
        border-right: calc( #{$breadcrumb-height} / 2 - 1px ) solid transparent;
        border-top:calc( #{$breadcrumb-height} / 2 - 1px ) solid transparent;
        border-bottom:calc( #{$breadcrumb-height} / 2 - 1px ) solid transparent;
        border-left:calc( #{$breadcrumb-height} / 2 - 1px ) solid #cccccc;
        z-index:10
      }
      &:after{
        top: 2px;
        left: 0;
        border-top:calc( #{$breadcrumb-height} / 2 - 2px ) solid transparent;
        border-right:calc( #{$breadcrumb-height} / 2 - 2px ) solid transparent;
        border-bottom: calc( #{$breadcrumb-height} / 2 - 2px ) solid transparent;
        border-left:calc( #{$breadcrumb-height} / 2 - 2px ) solid #FFFFFF;
        z-index: 12;
      }
    }
    li:first-child{
      &:before{
        border: none;
      }
    }
    li:last-child{
      color: #ffffff;
      background-color: #39A1F0;
      &:before{
        border-left: calc( #{$breadcrumb-height} / 2 - 1px ) solid #ffffff;
      }
      &:after{
        top: 0;
        left:unset;
        right: calc( #{$breadcrumb-height} / 0.86 * -1 );
        border-top:calc( #{$breadcrumb-height} / 2) solid transparent;
        border-right:calc( #{$breadcrumb-height} / 2) solid transparent;
        border-bottom: calc( #{$breadcrumb-height} / 2) solid transparent;
        border-left:calc( #{$breadcrumb-height} / 1.5) solid #39A1F0;
        z-index: 12;
        //content: '►';
      }
    }
  }
}
.cursor {
  cursor: pointer;
}
</style>
